﻿function setCodeCampCookie(c_name, value, expiredays) { /*alert('setting cookie');*/  var exdate = new Date(); exdate.setDate(exdate.getDate() + expiredays); document.cookie = c_name + '=' + escape(value) + ((expiredays == null) ? '' : ';expires=' + exdate.toGMTString()); }
function getCodeCampCookie(c_name) { /*alert('getting cookie');*/if (document.cookie.length > 0) { c_start = document.cookie.indexOf(c_name + '='); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(';', c_start); if (c_end == -1) c_end = document.cookie.length; return unescape(document.cookie.substring(c_start, c_end)); } } return ''; }

function initValidation() { jQuery('[id$=errmsg]').hide(); }

function requireField(obj) {
    var oField = jQuery('#' + obj);
    var oId = oField.attr('id');
    if (oField.val() == '') {
        var re = /\d+$/;
        if (re.test(oId)) {
            jQuery('#' + oId.replace(re.exec(oId), '') + '-errmsg' + re.exec(oId)).show();
        } else {
            jQuery('#' + oId + '-errmsg').show();
        }
        return 1;
    }
    return 0;
}

function stopRKey(evt) {
    var evt = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type == 'text')) { return false; }
} 

function AttachDateRange(startDate, endDate) {
    var currentTime = new Date();
    var _minDate = new Date(currentTime.getFullYear(), currentTime.getMonth(), currentTime.getDate());
    var _maxDate = new Date(currentTime.getFullYear() + 1, currentTime.getMonth(), currentTime.getDate());

    jQuery("#" + startDate + ",#" + endDate).datepicker({
        beforeShow: function customRange(input) {
            return { minDate: (input.id == endDate ? (jQuery("#" + startDate).datepicker("getDate") != null ? jQuery("#" + startDate).datepicker("getDate") : _minDate) : _minDate),
                maxDate: (input.id == startDate ? (jQuery("#" + endDate).datepicker("getDate") != null ? jQuery("#" + endDate).datepicker("getDate") : _maxDate) : _maxDate)
            };
        },
        defaultDate: +0,
        hideIfNoPrevNext: true,
        showOn: "both",
        firstDay: 1,
        changeFirstDay: false,
        buttonImage: '/images/calendar.png',
        buttonImageOnly: true
    });
}